package com.zodiac.alioth.service.biz;

import com.zodiac.alioth.common.util.FFmpegUtil;
import lombok.SneakyThrows;

import java.io.File;
import java.net.URL;

public class FFmpegTest {

    @SneakyThrows
    public static void main(String[] args) {
        FFmpegTest fFmpegTest = new FFmpegTest();
        String fFmpeg = fFmpegTest.getFFmpeg();
        // cmd 为待执行的命令行
        String inPath = "/Users/dasouche/Downloads/areyoureal.mp4";
        String outPaht = "/Users/dasouche/Downloads/output/areyoureal.mpd";
        String cmd = fFmpeg + " -i " + inPath + " -f dash " + outPaht;
        Process process = Runtime.getRuntime().exec(cmd);
        process.waitFor();
        System.out.println(process.exitValue());
    }

    private String getFFmpeg() {
        URL extra = this.getClass().getClassLoader().getResource("extra");
        System.out.println(extra.getPath());
        String extraPath = FFmpegUtil.getExtraPath();
        URL ffmpeg = getClass().getClassLoader().getResource("extra/ffmpeg");
        File f = null;
        if (ffmpeg != null) {
            f = new File(ffmpeg.getFile());
        }
        return f != null ? f.getAbsolutePath() : null;
    }

}
